#ifndef _EVENT_HANDLE_H_
#define _EVENT_HANDLE_H_

#include "session.h"

enum event_type {
    EVENT_EPOLLIN,
    EVENT_EPOLLOUT,
};

struct event_handle {
    int sock;
    unsigned int flags;
    enum session_type sess_type;
    void *data;
    struct event_loop *loop;
    struct event_handle *prev, *next;
};

struct event_loop {
    int fd;  // the epoll fd
    int running;
    int epoll_events_max;
    void *(*on_event_epollin)(struct event_handle *);
    void *(*on_event_epollout)(struct event_handle *);
    struct event_handle list;  // list head not use member data
};

int event_loop_init(struct event_loop *loop);
int event_loop_run(struct event_loop *loop);

struct event_handle *event_add(struct event_loop *loop, int sock, enum event_type type);
void event_del(struct event_handle *handle);

#endif
